package com.itheima.zuoye.zuoye1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
/*
- 获取ArrayList的字节码Class
- 获取add方法，Method
- 执行Method方法，传递实际参数字符串
- 打印ArrayList中的数据
 */

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<Integer> list = new ArrayList<>();
       Class aClass = Class.forName("java.util.ArrayList");
        Method add = aClass.getDeclaredMethod("add", Object.class);
        add.setAccessible( true);
        add.invoke(list,"张三");
        add.invoke(list,"李四");
        System.out.println( list.get(0));

    }
}
